package xyz.schwi.cels.entity;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * @author schwi
 * @date 2021/9/29 0029  09:46
 */
@Data
@NoArgsConstructor
public class Vocabulary extends Base {
    private String abbr;

    public Vocabulary(String en, List<String> cn, String abbr) {
        super(en, cn);
        setAbbr(abbr);
    }

    @Override
    public String save() {
        StringBuilder str = new StringBuilder();
        for (int i = 0; i < getCn().size(); i++) {
            if (i == getCn().size() - 1) {
                str.append(getCn().get(i));
                break;
            }
            str.append(getCn().get(i)).append(":");
        }
        return "#" + getEn() + "#" + str + "#" + (abbr == null ? "" : abbr) + "#" + getId();
    }

    @Override
    public String toString() {
        return super.toString() + (abbr != null ? ", 缩写是" + abbr : "");
    }
}
